import spyral
import pygame

import Dic;
import Story;
import Player;

class Menu(spyral.scene.Scene):
    def __init__(self):
        spyral.scene.Scene.__init__(self)
        self.camera = spyral.director.get_camera()
        self.group = spyral.sprite.Group(self.camera)
        
        title = spyral.sprite.Sprite()
        title.image = Dic.images['menu_title']
        title.rect.center = self.camera.get_rect().center
        
        instructions = spyral.sprite.Sprite()
        instructions.image = Dic.images['menu_instructions']
        instructions.rect.top = title.rect.bottom + 10
        instructions.rect.centerx = self.camera.get_rect().centerx
        
        self.gameNum = 0;
        self.group.add(title, instructions)
        
        self.player = Player.Player();
    
    def on_enter(self):
        bg = spyral.util.new_surface((960,640))
        bg.fill(Dic.colors['bg'])
        self.camera.set_background(bg)

          
    def render(self):
        self.group.draw()
        self.camera.draw()
        
    def update(self, tick):
        #input handler
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    exit(0)
                if event.key == pygame.K_SPACE:
                    spyral.director.push(Story.Story(self.player))
            if event.type == pygame.QUIT:
                spyral.director.pop();